package com.songVersion.jspot;

import java.io.IOException;

import com.google.code.jspot.Results;
import com.google.code.jspot.Spotify;
import com.google.code.jspot.Track;

public class JSpotSearch
{
	public static Track searchByTitleAndAuthor(String author, String title)
	{
		try
		{
			Spotify spotify = new Spotify();
			Results<Track> results = spotify.searchTrack(author, title);
			if (results == null || results.getItems().size() == 0)
				return null;
			else
				return results.getItems().get(0);
		} catch (IOException e)
		{
			e.printStackTrace();
			return null;
			//throw new RuntimeException(e);
		}
	}

	public static void main(String[] args)
	{
		
		  Track track = searchByTitleAndAuthor("The beatles", "Love me do");
		  System.out.println(track.getArtistName() + "-" + track.getName());
		/* 
		try
		{
			Spotify spotify = new Spotify();
			Results<Track> results = spotify.searchTrack("Weezer",
					"My name is Jonas");
			for (Track track : results.getItems())
			{
				System.out.printf("%.2f %s \n", track.getPopularity(), track
						.getId());
			}
		} catch (IOException e)
		{
			e.printStackTrace();
			throw new RuntimeException(e);
		}
		*/
	}
}
